package ups.proyecto.fin.hotel1.DAO;
/*
 * Hotelre1DAO
 *
 * version 1.0
 *
 *  19/02/2015
 *
 * Copyright
 */
import ups.proyecto.fin.hotel1.entidad.*;
//import ec.edu.ups.miproyecto.interfaz.Hotelres1Remoto;
import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.Query;


/**
 * EJB stateless built as a direct Access Object Data to manage the entity hotelres1.
 * @version 1.0
 * @author Ulloa Arias
 * 
 */
@Stateless
public class Hotelre1DAO{
	
/**
 * Injection of the JPA persistence context facilitates its reference from the EJB
 */
	@Inject
	private EntityManager em;
	
	
	/**
	 * CRUD method
	 * Procedure to persist an entity HotelRes1 in BD
	 * 
	 * @param t	Entity HotelRes1 to persist
	 */
		public void insert(Hotelres1 t){		
		em.persist(t);
	}

	/**
	 * CRUD method
	 * Procedure to update an entity HotelRes1 in BD
	 * 
	 * @param t Entity HotelRes1 to persist
	 */
		public void update(Hotelres1 t){		
		em.merge(t);		
	}
	
	/**
	 * 	 CRUD method
	 * Procedure to remove an entity HotelRes1 in BD
	 * @param t
	 */
	public void remove(Hotelres1 t){
		em.remove(t);
	}	
	
	/**
	 * CRUD method
	 * Procedure to retrieve an entity Hotelres1 of the BD based on the PK
	 * 
	 * @param Hotelres1		
	 * @return
	 */
	public Hotelres1 read(Integer Hotelres1){
		Hotelres1 t = em.find(Hotelres1.class, Hotelres1);
		return t;
	}
	
	/**
	 * Returns a collection of objects Hotelres1
	 * @return List<Hotelres1>		resulting collection
	 */
	public List<Hotelres1> getHotelres1(){
		
		String sql = "SELECT c "
				   + "  FROM Hotelres1 c";
		
		Query q =  em.createQuery(sql, Hotelres1.class);
		
		List<Hotelres1> lst = q.getResultList();
		
		return lst;
	}

	public Hotelres1 findByCodigo(Integer codigo){
		return em.find(Hotelres1.class, codigo);
	}
	
	/**
	 * Void Method
	 * Method to delete on entity HotelRes1 in BD
	 * @param Hotelres1Encontrado
	 */
	public void removeHotelres1(Hotelres1 Hotelres1Encontrado) {
		// TODO Auto-generated method stub
		
		Query query = em.createQuery("DELETE FROM Hotelres1 E where E.id= "+Hotelres1Encontrado.getHreId());
	    query.executeUpdate();
				
	}
		
}
